class ScheduledTaskLogsController < ApplicationController

  load_and_authorize_resource
  
  # GET /scheduled_task_logs
  # GET /scheduled_task_logs.xml
  def index
    save_redirect_back request.request_uri

    @scheduled_task_logs = search(params[:search_name], params[:page])

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @scheduled_task_logs }
    end
  end

  # GET /scheduled_task_logs/1
  # GET /scheduled_task_logs/1.xml
  def show
    @scheduled_task_log = ScheduledTaskLog.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @scheduled_task_log }
    end
  end

  def redirect_back
      redirect_back_or_default params[:url]
  end

  def redirect_back
      redirect_back_or_default params[:url]
  end
  
  #Pongo aca este metodo porque no quiero tocar el modelo que pertenece al plugin
  def search(search_task_name, page)
    items_per_page = count_record_per_page :scheduled_tasks_logs
    order = "start"

    conditions_clauses = []
    conditions_options = []

    if !search_task_name.nil? && search_task_name.size != 0
      conditions_clauses << "upper(tasks.name) like upper(?)"
      conditions_options << "%#{search_task_name}%"
    end
    conditions = [conditions_clauses.join(" AND "), conditions_options].flatten

    scheduled_task_logs = ScheduledTaskLog.paginate :per_page => items_per_page,:page => page, :joins => {:scheduled_task => :task}, :conditions => conditions, :order => order
    return scheduled_task_logs
  end
  
=begin
  # GET /scheduled_task_logs/new
  # GET /scheduled_task_logs/new.xml
  def new
    @scheduled_task_log = ScheduledTaskLog.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @scheduled_task_log }
    end
  end

  # GET /scheduled_task_logs/1/edit
  def edit
    @scheduled_task_log = ScheduledTaskLog.find(params[:id])
  end

  # POST /scheduled_task_logs
  # POST /scheduled_task_logs.xml
  def create
    @scheduled_task_log = ScheduledTaskLog.new(params[:scheduled_task_log])

    respond_to do |format|
      if @scheduled_task_log.save
        flash[:notice] = 'ScheduledTaskLog was successfully created.'
        format.html { redirect_to(@scheduled_task_log) }
        format.xml  { render :xml => @scheduled_task_log, :status => :created, :location => @scheduled_task_log }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @scheduled_task_log.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /scheduled_task_logs/1
  # PUT /scheduled_task_logs/1.xml
  def update
    @scheduled_task_log = ScheduledTaskLog.find(params[:id])

    respond_to do |format|
      if @scheduled_task_log.update_attributes(params[:scheduled_task_log])
        flash[:notice] = 'ScheduledTaskLog was successfully updated.'
        format.html { redirect_to(@scheduled_task_log) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @scheduled_task_log.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /scheduled_task_logs/1
  # DELETE /scheduled_task_logs/1.xml
  def destroy
    @scheduled_task_log = ScheduledTaskLog.find(params[:id])
    @scheduled_task_log.destroy

    respond_to do |format|
      format.html { redirect_to(scheduled_task_logs_url) }
      format.xml  { head :ok }
    end
  end
=end
end
